package com.hongye.area.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.Query;

import com.hongye.area.dao.MetroDao;
import com.hongye.area.entity.MetroEntity;
import com.hongye.area.service.MetroService;


@Service("metroService")
public class MetroServiceImpl extends ServiceImpl<MetroDao, MetroEntity> implements MetroService {

    @Autowired
    MetroDao metroDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params, MetroEntity metroEntity) {
        QueryWrapper<MetroEntity> qw = new QueryWrapper<>();
        //省份
        if (metroEntity.getProvinceId() != null && metroEntity.getProvinceId() != 0) {
            qw.eq("province_id",metroEntity.getProvinceId());
        }
        //市级
        if (metroEntity.getCity() != null && metroEntity.getCity() != 0) {
            qw.eq("city",metroEntity.getCity());
        }
        //地铁线模糊查询
        if (metroEntity.getMetroName() != null && !"".equals(metroEntity.getMetroName())) {
            qw.like("metro_name",metroEntity.getMetroName());
        }
        qw.last("order by sort asc");
        IPage<MetroEntity> page = this.page(
                new Query<MetroEntity>().getPage(params),
                qw
        );

        return new PageUtils(page);
    }

    @Override
    public int updateState(Integer id, Integer state) {

        return metroDao.updateState(id,state);
    }

}